package com.ruoyi.tongyan.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tongyan.domain.TAchievementOutput;
import com.ruoyi.tongyan.service.ITAchievementOutputService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 科研成果主Controller
 * 
 * @author ruoyi
 * @date 2025-04-20
 */
@RestController
@RequestMapping("/tongyan/output")
public class TAchievementOutputController extends BaseController
{
    @Autowired
    private ITAchievementOutputService tAchievementOutputService;

    /**
     * 查询科研成果主列表
     */
    @PreAuthorize("@ss.hasPermi('tongyan:output:list')")
    @GetMapping("/list")
    public TableDataInfo list(TAchievementOutput tAchievementOutput)
    {
        startPage();
        List<TAchievementOutput> list = tAchievementOutputService.selectTAchievementOutputList(tAchievementOutput);
        return getDataTable(list);
    }

    /**
     * 导出科研成果主列表
     */
    @PreAuthorize("@ss.hasPermi('tongyan:output:export')")
    @Log(title = "科研成果主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TAchievementOutput tAchievementOutput)
    {
        List<TAchievementOutput> list = tAchievementOutputService.selectTAchievementOutputList(tAchievementOutput);
        ExcelUtil<TAchievementOutput> util = new ExcelUtil<TAchievementOutput>(TAchievementOutput.class);
        util.exportExcel(response, list, "科研成果主数据");
    }

    /**
     * 获取科研成果主详细信息
     */
    @PreAuthorize("@ss.hasPermi('tongyan:output:query')")
    @GetMapping(value = "/{achievementId}")
    public AjaxResult getInfo(@PathVariable("achievementId") Long achievementId)
    {
        return success(tAchievementOutputService.selectTAchievementOutputByAchievementId(achievementId));
    }

    /**
     * 新增科研成果主
     */
    @PreAuthorize("@ss.hasPermi('tongyan:output:add')")
    @Log(title = "科研成果主", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TAchievementOutput tAchievementOutput)
    {
        return toAjax(tAchievementOutputService.insertTAchievementOutput(tAchievementOutput));
    }

    /**
     * 修改科研成果主
     */
    @PreAuthorize("@ss.hasPermi('tongyan:output:edit')")
    @Log(title = "科研成果主", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TAchievementOutput tAchievementOutput)
    {
        return toAjax(tAchievementOutputService.updateTAchievementOutput(tAchievementOutput));
    }

    /**
     * 删除科研成果主
     */
    @PreAuthorize("@ss.hasPermi('tongyan:output:remove')")
    @Log(title = "科研成果主", businessType = BusinessType.DELETE)
	@DeleteMapping("/{achievementIds}")
    public AjaxResult remove(@PathVariable Long[] achievementIds)
    {
        return toAjax(tAchievementOutputService.deleteTAchievementOutputByAchievementIds(achievementIds));
    }
}
